<style type="text/css">
    .layui-table-body {
        overflow-x: auto;
    }

    .layui-table-cell {
        font-size: 12px;
    }
</style>
<div class="page-toolbar">
    <div class="page-filter fr">
        <form class="layui-form layui-form-pane" action="{:url()}" id="hisiSearch" method="get">
            <div class="layui-form-item">
                <label class="layui-form-label">搜索</label>
                <div class="layui-input-inline">
                    <input type="text" name="keyword" value="" lay-verify="required" placeholder="名称" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </form>
    </div>
    <div class="layui-btn-group fl">
        <!--<a href="{:url('createCategories')}" class="layui-btn layui-btn-primary layui-icon layui-icon-add-circle-fine">&nbsp;添加</a>-->
        <a data-href="{:url('status?table=group_categories&val=1')}"
           class="layui-btn layui-btn-primary j-page-btns layui-icon layui-icon-play" data-table="dataTable">
            &nbsp;启用</a>
        <a data-href="{:url('status?table=group_categories&val=0')}"
           class="layui-btn layui-btn-primary j-page-btns layui-icon layui-icon-pause" data-table="dataTable">
            &nbsp;禁用</a>
        <a data-href="{:url('del?table=group_categories')}"
           class="layui-btn layui-btn-primary j-page-btns confirm layui-icon layui-icon-close red">&nbsp;删除</a>
    </div>
</div>
<form id="pageListForm">
    <div class="layui-form">
        <table id="dataTable"></table>
        <script type="text/html" id="recommendTpl">
            <input type="checkbox" name="is_recommend" value="{{ d.is_recommend }}" lay-skin="switch"
                   lay-filter="switchStatus" lay-text="是|否" {{ d.is_recommend== 1
                   ? 'checked' : '' }} data-href="{:url('status')}?table=group_posts&field=is_recommend&id={{ d.id }}">
        </script>
        <script type="text/html" id="essenceTpl">
            <input type="checkbox" name="is_essence" value="{{ d.is_essence }}" lay-skin="switch"
                   lay-filter="switchStatus" lay-text="是|否" {{ d.is_essence== 1
                   ? 'checked' : '' }} data-href="{:url('status')}?table=group_posts&field=is_essence&id={{ d.id }}">
        </script>
        <script type="text/html" id="disabledTpl">
            <input type="checkbox" name="disabled" value="{{ d.disabled }}" lay-skin="switch" lay-filter="switchStatus"
                   lay-text="正常|关闭" {{ d.disabled== 1
                   ? 'checked' : '' }} data-href="{:url('status')}?table=group_posts&field=disabled&id={{ d.id }}">
        </script>
        <script type="text/html" title="操作按钮模板" id="buttonTpl">
            <a href="{:url('view')}?postId={{ d.id }}"
               class="layui-btn layui-btn-xs layui-btn-normal">查看</a><!--<a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal">修改</a>-->
            <a href="{:url('del')}?id={{ d.id }}&table=group_posts" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
        </script>
    </div>
</form>
{include file="block/layui" /}
<script type="text/javascript">
    layui.use(['table'], function () {
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            , url: '{:url()}' //数据接口
            , page: true //开启分页
            , limit: 20
            , text: {
                none: '暂无相关数据'
            }
            , cols: [[ //表头
                {type: 'checkbox'}
                , {
                    field: 'has_group', title: '所属星球', width: 100, templet: function (d) {
                        return d.has_group.name;
                    }
                }
                , {field: 'body', title: '内容'}
                , {
                    field: 'has_user', title: '作者', width: 100, templet: function (d) {
                        return d.has_user.nick;
                    }
                }
                , {
                    field: 'type', title: '帖子类型', width: 100, templet: function (d) {
                        if (d.type == 1) {
                            return "普通主题";
                        } else if (d.type == 2) {
                            return "提问主题";
                        } else if (d.type == 3) {
                            return "回答主题";
                        }
                    }
                }
                , {field: 'likes_count', title: '点赞数', width: 70}
                , {field: 'comments_count', title: '评论数', width: 70}
                , {field: 'is_recommend', title: '是否推荐', width: 80, templet: '#recommendTpl'}
                , {field: 'is_essence', title: '是否精华', width: 80, templet: '#essenceTpl'}
                , {field: 'ctime', title: '发布时间', width: 140}
                , {field: 'disabled', title: '显示状态', width: 90, templet: '#disabledTpl'}
                , {title: '操作', width: 110, templet: '#buttonTpl'}
            ]]
        });
    });
</script>